package com.zx.lc.rag;

import com.zx.lc.service.Assistant;
import dev.langchain4j.data.document.Document;
import dev.langchain4j.data.document.loader.FileSystemDocumentLoader;
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.ollama.OllamaChatModel;
import dev.langchain4j.rag.content.retriever.EmbeddingStoreContentRetriever;
import dev.langchain4j.service.AiServices;
import dev.langchain4j.store.embedding.EmbeddingStoreIngestor;
import dev.langchain4j.store.embedding.inmemory.InMemoryEmbeddingStore;
import java.time.Duration;
import java.util.List;
import org.springframework.stereotype.Service;

@Service
public class _1_RagSimpleService {

    public static void main(String[] args) {
        List<Document> documents = FileSystemDocumentLoader.loadDocumentsRecursively("D:\\llm\\rag-demo");
        InMemoryEmbeddingStore<TextSegment> embeddingStore = new InMemoryEmbeddingStore<>();
        EmbeddingStoreIngestor.ingest(documents, embeddingStore);

        ChatLanguageModel chatModel = OllamaChatModel.builder()
                .baseUrl("http://192.168.3.99:11434")
                .timeout(Duration.ofSeconds(3600))
                .modelName("qwen2.5:7b")
                .build();

        Assistant assistant = AiServices.builder(Assistant.class)
                .chatLanguageModel(chatModel)
                .contentRetriever(EmbeddingStoreContentRetriever.from(embeddingStore))
                .build();

        String chat = assistant.chat("周雨彤是谁？帮我查下这个人的信息");
        System.out.println(chat);
    }


}
